import matplotlib.pyplot as plt
import csv

import numpy as np
from scipy.interpolate import make_interp_spline

'''读取csv文件'''


def readcsv(files):
    csvfile = open(files, 'r')
    plots = csv.reader(csvfile, delimiter=',')
    x = []
    y = []
    # 读取csv文件中2,3列的数据，且转化为float类型
    for row in plots:
        y.append(float(row[2]))
        x.append(float(row[1]))
    return x, y


# auc
x_auc = r'C:\Users\admin\Desktop\对比实验结果\AUC\run-Entity+AU-tag-Validation_AUC.csv'
x1_auc = r"C:\Users\admin\Desktop\对比实验结果\AUC\run-Entity-tag-Validation_AUC.csv"
# mrr
x_mrr = r'C:\Users\admin\Desktop\对比实验结果\MRR\run-Entity+AU-tag-Validation_MRR.csv'
x1_mrr = r"C:\Users\admin\Desktop\对比实验结果\MRR\run-Entity-tag-Validation_MRR.csv"
# ndcg@10
x_ndcg = r'C:\Users\admin\Desktop\对比实验结果\MRR\run-Entity+AU-tag-Validation_MRR.csv'
x1_ndcg = r"C:\Users\admin\Desktop\对比实验结果\MRR\run-Entity-tag-Validation_MRR.csv"

x, y = readcsv(x_ndcg)
x_smooth = np.linspace(min(x), max(x), 20)
y_smooth = make_interp_spline(x, y)(x_smooth)
plt.plot(x_smooth, y_smooth, label='with activate unit', marker='o', markersize='7', markeredgewidth='1', markevery=3,
         linewidth='1.5')

x1, y1 = readcsv(x1_ndcg)
x1_smooth = np.linspace(min(x1), max(x1), 20)
y1_smooth = make_interp_spline(x1, y1)(x1_smooth)
plt.plot(x1_smooth, y1_smooth, label='no activate unit', marker='*', markersize='7', markeredgewidth='1', markevery=3,
         linewidth='1.5')

plt.xlabel("step", fontsize=15)
plt.ylabel("ndcg@10", fontsize=15)
plt.legend()
plt.show()
